

package cn.shengchao.controler;

import cn.shengchao.util.helper.LoginHelper;
import cn.shengchao.examstar.account.ohs.local.appservice.AccountAppService;
import cn.shengchao.examstar.account.ohs.local.appservice.message.AccountDto;
import cn.shengchao.examstar.account.ohs.local.appservice.message.WithdrawDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/account")
public class AccountController {

    @Autowired
    private AccountAppService accountAppService;

    @GetMapping("balance")
    public AccountDto balance() {
        Long uid = LoginHelper.getLoginUser().getId();
        return accountAppService.balance(uid);
    }

    @PostMapping("withdraw")
    public void withdraw(@RequestBody WithdrawDto withdrawDto) {
        Long uid = LoginHelper.getLoginUser().getId();
        accountAppService.withdraw(uid, withdrawDto.getAmount(), withdrawDto.getBackCardId());
    }

}
